package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.StrategyCommentLike;
import cn.wolfcode.trip.base.mapper.StrategyCommentLikeMapper;
import cn.wolfcode.trip.base.service.IStrategyCommentLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 给攻略评论点赞的service
 */
@Service
public class StrategyCommentLikeServiceImpl implements IStrategyCommentLikeService {

    @Autowired
    private StrategyCommentLikeMapper commentLikeMapper;

    /**
     * 点赞保存
     * @param commentLike
     */
    @Override
    public void save(StrategyCommentLike commentLike) {
        commentLikeMapper.insert(commentLike);
    }

    /**
     * 点赞取消
     * @param commentLike
     */
    @Override
    public void updateStatus(StrategyCommentLike commentLike) {
        commentLikeMapper.updateStatus(commentLike);
    }

    /**
     * 统计某条攻略评论被点赞的次数
     * @param commentId
     * @return
     */
    @Override
    public int countNumByCommentId(Long commentId) {
        int num = commentLikeMapper.countNumByCommentId(commentId);
        return num;
    }

    @Override
    public List<Long> getAllStatusByLikerId(Long likerId) {
        List<Long> commentsId = commentLikeMapper.getAllStatusByLikerId(likerId);
        return commentsId;

    }

    @Override
    public void delete(StrategyCommentLike commentLike) {
        commentLikeMapper.delete(commentLike);
    }

    /**
     * 判断当前用户是否对该条评论点了赞
     * @param commentLike
     * @return
     */
    @Override
    public int getStatusByLikerId(StrategyCommentLike commentLike) {
        Integer status = commentLikeMapper.getStatusByLikerId(commentLike);
        if (status==null){
            return -1;
        }
        return status;
    }
}
